package com.qf.blogsystem.service.impl;

import com.qf.blogsystem.core.dao.BaseDao;
import com.qf.blogsystem.core.service.impl.BaseServiceImpl;
import com.qf.blogsystem.dao.DiscussPostDao;
import com.qf.blogsystem.dao.impl.DiscussPostDaoImpl;
import com.qf.blogsystem.entity.DiscussPost;
import com.qf.blogsystem.service.DiscussPostService;
import com.qf.blogsystem.vo.DiscussPostVo;

import java.util.Date;
import java.util.List;

/**
 * @author Crazy
 * @version 1.0
 * @description: 帖子业务层实现类
 * @date 2022/12/6 10:36
 */
public class DiscussPostServiceImpl extends BaseServiceImpl<DiscussPost> implements DiscussPostService {
    /**
     * 创建帖子Dao实现类对象
     */
    private DiscussPostDao discussPostDao=new DiscussPostDaoImpl();

    @Override
    protected BaseDao<DiscussPost> getBaseDao() {
        return discussPostDao;
    }

    /**
     * 添加帖子信息
     * @param discussPost
     * @return boolean
     * @throws Exception
     */
    @Override
    public boolean save(DiscussPost discussPost) throws Exception {
        discussPost.setStatus(0);
        discussPost.setType(0);
        discussPost.setCreateTime(new Date());
        discussPost.setScore(0.0);
        discussPost.setCommentCount(0);
        return super.save(discussPost);
    }

    /**
     * 查询所有帖子信息
     * @return List<DiscussPostVo>
     * @throws Exception
     */
    @Override
    public List<DiscussPostVo> discussPostList() throws Exception {
        return discussPostDao.selectAllDiscussPost();
    }
}
